﻿using System;
using UnityEngine;

namespace UniRx.Triggers
{
	// Token: 0x02000447 RID: 1095
	public abstract class ObservableTriggerBase : MonoBehaviour
	{
		// Token: 0x06001706 RID: 5894 RVA: 0x00060FB6 File Offset: 0x0005F3B6
		private void Awake()
		{
			this.calledAwake = true;
			if (this.awake != null)
			{
				this.awake.OnNext(Unit.Default);
				this.awake.OnCompleted();
			}
		}

		// Token: 0x06001707 RID: 5895 RVA: 0x00060FE8 File Offset: 0x0005F3E8
		public IObservable<Unit> AwakeAsObservable()
		{
			if (this.calledAwake)
			{
				return Observable.Return(Unit.Default);
			}
			Subject<Unit> result;
			if ((result = this.awake) == null)
			{
				result = (this.awake = new Subject<Unit>());
			}
			return result;
		}

		// Token: 0x06001708 RID: 5896 RVA: 0x00061026 File Offset: 0x0005F426
		private void Start()
		{
			this.calledStart = true;
			if (this.start != null)
			{
				this.start.OnNext(Unit.Default);
				this.start.OnCompleted();
			}
		}

		// Token: 0x06001709 RID: 5897 RVA: 0x00061058 File Offset: 0x0005F458
		public IObservable<Unit> StartAsObservable()
		{
			if (this.calledStart)
			{
				return Observable.Return(Unit.Default);
			}
			Subject<Unit> result;
			if ((result = this.start) == null)
			{
				result = (this.start = new Subject<Unit>());
			}
			return result;
		}

		// Token: 0x0600170A RID: 5898 RVA: 0x00061096 File Offset: 0x0005F496
		private void OnDestroy()
		{
			this.calledDestroy = true;
			if (this.onDestroy != null)
			{
				this.onDestroy.OnNext(Unit.Default);
				this.onDestroy.OnCompleted();
			}
			this.RaiseOnCompletedOnDestroy();
		}

		// Token: 0x0600170B RID: 5899 RVA: 0x000610CC File Offset: 0x0005F4CC
		public IObservable<Unit> OnDestroyAsObservable()
		{
			if (this == null)
			{
				return Observable.Return(Unit.Default);
			}
			if (this.calledDestroy)
			{
				return Observable.Return(Unit.Default);
			}
			Subject<Unit> result;
			if ((result = this.onDestroy) == null)
			{
				result = (this.onDestroy = new Subject<Unit>());
			}
			return result;
		}

		// Token: 0x0600170C RID: 5900
		protected abstract void RaiseOnCompletedOnDestroy();

		// Token: 0x04000CD5 RID: 3285
		private bool calledAwake;

		// Token: 0x04000CD6 RID: 3286
		private Subject<Unit> awake;

		// Token: 0x04000CD7 RID: 3287
		private bool calledStart;

		// Token: 0x04000CD8 RID: 3288
		private Subject<Unit> start;

		// Token: 0x04000CD9 RID: 3289
		private bool calledDestroy;

		// Token: 0x04000CDA RID: 3290
		private Subject<Unit> onDestroy;
	}
}
